home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / idioms.lha / idioms / 3-1.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  1KB  |  38 lines

  1. /* Copyright (c) 1992 by AT&T Bell Laboratories. */
  2. /* Advanced C++ Programming Styles and Idioms */
  3. /* James O. Coplien */
  4. /* All rights reserved. */
  5.  
  6. class String {
  7. public:
  8.     // the public user interface to a String:
  9.  
  10.     // redefine "+" to mean catenation, two cases:
  11.     friend String operator+(const char*, const String&);
  12.     String operator+(const String&) const;
  13.     int length() const;      // length of string in characters
  14.     // . . . .               // other interesting operations
  15.  
  16.     // boilerplate member functions:
  17.  
  18.     String();                // default constructor
  19.     String(const String&);   // constructor to initialize a new
  20.                              //   string from an existing one
  21.     String& operator=(const String&);  // assignment
  22.     ~String();               // destructor
  23.  
  24.     /*
  25.      * These operators are typical of the kinds of customized
  26.      * behaviors a user can define for a type.  These are
  27.      * examples suitable for a String class.
  28.      */
  29.  
  30.     String(const char *);    // initialize from a "C string"
  31. private:
  32.     char *rep;               // implementation data and
  33.                              //    internal functions
  34.                              //    (here, represent internals
  35.                              //    as a good old C string)
  36.  
  37. };
  38.